<#include '/admin/header.html' >
<#assign dateFormat="com.enation.framework.directive.DateformateDirective"?new()>
<style>
#searchKeyword	{
	border: 1px ridge #e8e9ee;
    border-radius: 2px;
    line-height: 28px;
    margin-top: 8px;
    padding: 0 0 0 5px;
    vertical-align: middle;
    width: 300px;
}
.searchAdvanced	{
	background-color: white;
    border: 1px ridge #e5e5e5;
    box-shadow: -2px 0 5px #e5e5e5;
    display: none;
    position: absolute;
    right: 28px;
    text-align: left;
    top: 62px;
    width: 480px;
    z-index: 100;
}
.layui-form-item{
	display: inline-block;
    margin-bottom: 0;
    width: 49%;
}
.layui-input{
 	-moz-border-bottom-colors: none;
    -moz-border-left-colors: none;
    -moz-border-right-colors: none;
    -moz-border-top-colors: none;
    border-color: currentcolor currentcolor #e6e6e6;
    border-image: none;
    border-style: none none solid;
    border-width: 0 0 1px;
 }
.layui-table {
	margin:0px;
}
</style>
<div id="loading"></div>
<div class="admin-main">
<script type="text/javascript" src="${ctx}/statics/e_tools/js/jquery.goodsCatsSelect.js"></script>
	<form id="gridform" method="post">
	<input type="hidden" name="tagid" value="${tagid }"/>
	<input type="hidden" name="tagids" value=""/>
	<div class="table_control">
		<div class='buttonArea'>
			<div class="table_opera">
				<span id="searchbtn">
					 <button type="button" title="添加选中" class="layui-btn layui-btn-primary"  onclick="controlGoods()" style="width:55px;"> <i class="layui-icon">&#xe641;</i></button>
				</span>
			</div>
			<!-- 搜索区域操作 -->
			<div class="table_search">
				<span style="float: right;"> 
					<span id="simpleSearch">
						<input id="searchKeyword" class="input_text" type="text" maxlength="50" value="" size="30"
						placeholder="请输入模糊关键字" name="searchKeyWord" style="height:25px;"> 
						<a href="javascript:void(0)" class="layui-btn layui-btn-primary layui-btn-small" 
						data-options="plain:true" onclick="searchGoods()" style="margin-top:7px;"><i class="layui-icon">&#xe615;</i></a>
					</span>
					<!--   高级搜索区域 -->
					<a href="javascript:void(0)" class="button layui-btn layui-btn-primary layui-btn-small"
					data-options="plain:true" id="aAdvanced" style="margin-top:7px;">高级搜索</a>
				</span>
			</div>
		</div>
	</div>
		<div style="display: block;" class="searchAdvanced" >
		<input id="Advanced" name="Advanced" type="hidden" value="0" />
			<div class="content_title"><span>高级搜索</span></div>
			<table class="layui-table" width="98%" border="0" cellspacing="0" cellpadding="8">
				 <div class="layui-form-item">
					<label class="layui-form-label" >商品名称:</label>
					 <div class="layui-input-block">
						<input type="text" value="${name!''}" id="name"  class="input_text layui-input" style="width: 95%;" >
					</div>
				</div>
				 <div class="layui-form-item">
					  <label class="layui-form-label" >商品编号:</label>
					  <div class="layui-input-block">
						<input type="text" value="${name!''}" id="sn"class="input_text layui-input" style="width: 95%;">
					  </div>
				 </div>
				 <div class="layui-form-item">
				 	 <label class="layui-form-label">类别:</label>
					  <div class="layui-input-block">       
						<input type="text" id="cat_name" value="" style="width: 200px;height: 25px;position: relative;" />
						<input type="hidden" id="cat_id" name="cat_id" value="" />						
					</div>
				 </div>
				 <ul>
				 	<li class="reset">
				 		<button type="reset" id="reset_btn" class="layui-btn  layui-btn-primary">重置</button>
				 	</li>
					<li class="submit">
						 <button id="submit_btn"  type="button" class="layui-btn layui-btn-primary" lay-submit="" onclick="searchGoods()" ">开始搜索</a>
					</li>
				</ul>
				
			</table>
		</div>
	<div class="clear height10"></div>
		<div class="shadowBoxWhite tableDiv">
			<!--表格区域  -->	 
			<table class="layui-table site-table table-hover"  id="goodsdata" width="100%" >
				<thead>
					<tr>
						<th><input type='checkbox'  class='btn-checkall fly-checkbox' id='selected-all'></th>
						<th width="120px">商品编号</th>
						<th width="350px">商品名称</th>
						<th width="100px">分类</th>
						<th width="100px">销售价格</th>
						<th width="50px">上架</th>
						<th width="120px">品牌</th>
						<th width="120px">上架时间</th>
					</tr>
				</thead>
			</table>
		</div>
	</form>
</div>
<script type="text/javascript">
function market_enable(value,row,index){
	var val;
	if(value==1){val="是";}else if(value==0){val="否";}
	return val;
}
function formatMoney(value,row,index){
	var val="￥"+value;
	return val;
}
function formatTime(value,row,index){
	return getFormatDateByLong(value, "yyyy-MM-dd hh:mm:ss");
}
var table;
$(function(){
	$(".searchAdvanced").hide();
	//高级查询按钮
    $("#aAdvanced").click(function () {
        if ($("#Advanced").val() == "0") {
            $("#Advanced").val(1);
            $("#simpleSearch").hide();
            $("#aAdvanced").addClass("searchAdvancedS");
        } else {
            $("#Advanced").val(0);
            $("#simpleSearch").show();
            $("#aAdvanced").removeClass("searchAdvancedS");
        }
        $(".searchAdvanced").toggle();
    });
	
    table = $('#goodsdata').DataTable({
		"language": {
	        "url": "${staticserver}/media/zh_CN.txt"
	    },
	    "processing": true,
	    "serverSide": true,
	    "ordering": false,
	    "searching": false,
	    "lengthChange": false,
	    ajax: {
	        //指定数据源
	        type:"post",
	        url: '${ctx}/shop/admin/goods/list-json.do',
	    },
	    columns: [ //定义列	  
	        {"data": function (obj) {
                return '<input type="checkbox" name="id" class="fly-checkbox" value='+ obj.goods_id + '>';
            }},
	        {data: "sn"},
	        {data: "name"},
	        {data: "cat_name"},
	        {data: null,"render":function(data, type, row) {
	        	return formatMoney(data.price,row,type);		
	       	}},
	       	{data: null,"render":function(data, type, row) {
	        	return market_enable(data.market_enable,row,type);		
	       	}},
	        {data: "brand_name"},
	       	{data: null,"render":function(data, type, row) {
	        	return formatTime(data.last_modify,row,type);		
	       	}}	        
	     ]
	});
    
  //高级搜索
	$("#submit_btn").click(function(){
		searchGoods(table);
	});
	
  
  //分类选择
	 $('#cat_name').goodsCatsSelect({
		 	top: 180,
		 	left:800,
		 	zIndex: 998,
          callback: function (cat) {
             var cat_id = cat.cat_id;
             var cat_name = cat.string;
             $("#cat_name").val(cat_name);
             $("#cat_id").val(cat_id);
          }
    });
})		

//搜索
function searchGoods(){
	var searchtype = $("#Advanced").val()
	var keyword = $("#searchKeyword").val();
	var name = $("#name").val();
	var sn = $("#sn").val();
	var catid = $("#cat_id").val();
	table.ajax.url("${ctx}/shop/admin/goods/list-json.do?keyword="+keyword+"&stype="+searchtype+"&name="+name+"&sn="+sn+"&catid="+catid).load();
}


function controlGoods(){
	var obj = document.getElementsByName("id");
	var check_val = [];
	for(k in obj){
	   if(obj[k].checked){
	        check_val.push(obj[k].value);         	
	    }
	}
	if(check_val.length<1){
		layer.msg("请选择要添加商品");
		return;
	}
	var options = {
			url : "${ctx}/shop/admin/goods-show/batch-add.do?ajax=yes&goods_id="+check_val,
			type : "POST",
			dataType : 'json',
			success : function(result) {
				
				if(result.result==1){	
					$.Loading.success("添加成功");
					location.reload();     
				}
				if(result.result==0){
					$.Loading.error(result.message);
				}
			},
			error : function(e) {
				$.Loading.error("出现错误 ，请重试");
			}
		};
		$('#gridform').ajaxSubmit(options);	
}
</script>

<#include '/admin/footer.html' >


